package model

import (
	"gorm.io/gorm"
	"service/basic/config"
	"time"
)

type Home struct {
	Id        uint32         `gorm:"column:id;type:int UNSIGNED;primaryKey;not null;" json:"id"`
	Module    string         `gorm:"column:module;type:varchar(255);comment:模块;not null;" json:"module"` // 模块
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (h *Home) TableName() string {
	return "home"
}

// 查看
func (h *Home) List() (home []*Home, err error) {
	err = config.DB.Find(&home).Error
	return
}

// 隐藏
func (h *Home) Remove(db *gorm.DB) error {
	return config.DB.Where("module = ?", h.Module).Delete(&h).Error
}
